'use strict';
const {
  makeRequest,
  mixArgs,
  mixArgs_nodefault,
  add,
} = require('../src/main.js');

var assert = require('assert');
require('mocha-sinon');

describe('Better Unicode Support', function () {
  afterEach(function () {});
  beforeEach(function () {
    //this.sinon.stub(console, 'log');
    this.sinon.spy(console, 'log');
  });

  it('should ', function (done) {
    makeRequest('/foo');
    assert.strictEqual(console.log.callCount, 3);
    assert.strictEqual(console.log.args[0][0], '/foo');
    assert.strictEqual(console.log.args[1][0], 2000);
    assert.strictEqual(console.log.args[2][0].name, 'callback');

    makeRequest('/foo', 100);
    assert.strictEqual(console.log.callCount, 6);
    assert.strictEqual(console.log.args[3][0], '/foo');
    assert.strictEqual(console.log.args[4][0], 100);
    assert.strictEqual(console.log.args[5][0].name, 'callback');

    makeRequest('/foo', undefined);
    assert.strictEqual(console.log.callCount, 9);
    assert.strictEqual(console.log.args[6][0], '/foo');
    assert.strictEqual(console.log.args[7][0], 2000);
    assert.strictEqual(console.log.args[8][0].name, 'callback');

    mixArgs('a');
    assert.strictEqual(console.log.callCount, 14);
    assert.strictEqual(console.log.args[9][0], 1); //arguments.length
    assert.strictEqual(console.log.args[10][0], true); //first === arguments[0]
    assert.strictEqual(console.log.args[11][0], false); //second === arguments[1]
    assert.strictEqual(console.log.args[12][0], false); //first === arguments[0]
    assert.strictEqual(console.log.args[13][0], false); //second === arguments[1]

    mixArgs_nodefault('a', 'b'); //严格模式下，arguments与参数名称绑定
    assert.strictEqual(console.log.callCount, 19);
    assert.strictEqual(console.log.args[14][0], 2); //arguments.length
    assert.strictEqual(console.log.args[15][0], true); //first === arguments[0]
    assert.strictEqual(console.log.args[16][0], true); //second === arguments[1]
    assert.strictEqual(console.log.args[17][0], false); //first === arguments[0]
    assert.strictEqual(console.log.args[18][0], false); //second === arguments[1]

    done();
  });
  it('should Computed Property Names', function (done) {
    let person = {};
    let lastname = 'last name';
    person[lastname] = 'li';

    assert.strictEqual(person['last name'], 'li');
    assert.strictEqual(person[lastname], 'li');
    done();
  });
  it('should 属性初始化', function (done) {
    function init(name, age) {
      return {
        name,
        age,
      };
    }

    let person = init('li', 28);

    assert.strictEqual(person['name'], 'li');
    assert.strictEqual(person['age'], 28);
    done();
  });
  it('should create', function (done) {
    const person = {
      isHuman: false,
      printIntroduction: function () {
        console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
      },
    };

    const me = Object.create(person);
    done();
  });
  it('should supper', function (done) {
    let person = {
      getGreeting() {
        return 'Hello';
      },
    };
    let dog = {
      getGreeting() {
        return 'Woof';
      },
    };
    let friend = {
      getGreeting() {
        //return Object.getPrototypeOf(this).getGreeting.call(this) + ', hi!';
        return super.getGreeting.call(this) + ', hi!';
      },
    };

    Object.setPrototypeOf(friend, person);

    assert.strictEqual(friend.getGreeting(), "Hello, hi!");
    assert.strictEqual(Object.getPrototypeOf(friend), person);
    done();
  });
});
